package com.yunxin.customui.service.handlerimpl.table.trhandlerimpl;

import com.yunxin.customui.bean.table.TdBean;
import com.yunxin.customui.bean.table.TrBean;
import com.yunxin.customui.myinterface.table.ITrHandler;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 根据行数字差异变色
 * 还没写完
 *
 * @author LGY
 * @date 2021/10/11
 */
@Service
public class DifChangeColorImpl implements ITrHandler<String[]> {

    /**
     * 处理
     *
     * @param trBean 一行数据
     * @param params 参数
     */
    @Override
    public void handle(TrBean trBean ,String[] params) {
        LinkedList<TdBean> tdBeans = trBean.getTdBeans();
        List<Double> doubles = new ArrayList<>();
        for (TdBean tdBean : tdBeans) {
            String value = tdBean.getValue();
            try {
                doubles.add(Double.parseDouble(value));
            }catch (NumberFormatException ignored){
            }
        }
        boolean compare = compare(doubles, Double.parseDouble(params[0]));
        if (!compare){
            for (TdBean tdBean : tdBeans) {
                tdBean.getStyle().setColor(params[1]);
            }
        }
    }

    /**
     * 比较
     *
     * @param data 数据
     * @param dif  dif
     * @return boolean
     */
    public boolean compare(List<Double> data, Double dif){
        return false;
    }
}
